-
-
Notifications
You must be signed in to change notification settings - Fork 664
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
STYLE: Clean-up ByteSwapper, using private SwapBytes
helper function
#4855
STYLE: Clean-up ByteSwapper, using private SwapBytes
helper function
#4855
Conversation
d05afc5
to
9d241e9
Compare
} | ||
else | ||
{ | ||
itkGenericExceptionMacro("Cannot swap number of bytes requested"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a run-time exception for a "constexpr" conditional?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed! Only the condition of an if constexpr (condition) { ... }
must be evaluated at compile-time. Anything inside the if
or else
clause may be evaluated at run-time.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of this exception, we might also just trigger a compile-time assert failure (static_assert
). But obviously, that would change the behavior of ByteSwapper (at least for an unsupported number of bytes). It might be considered an improvement, to replace the exception with a static_assert
, of course. Would you like that?
We might just do:
static_assert(numberOfBytes == 2 || numberOfBytes == 4 || numberOfBytes == 8);
Would you like that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. I think it would be an improvement and help detect errors in code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Honestly it would be fine to me to also support other number of bytes. Why not support numberOfBytes == 16
, for example? For example, when a user wants to swap 128-bit integers...!
I think the original itkGenericExceptionMacro("Cannot swap number of bytes requested")
was there just because we only had three of those helper functions: Swap2
, Swap4
, and Swap8
. Instead, we can now support just any number of bytes! Would you like that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Still broken, now it's itkVTKPolyDataMeshIO, at https://open.cdash.org/viewBuildError.php?type=1&buildid=9915657:
in instantiation of function template specialization 'itk::VTKPolyDataMeshIO::ReadPointsBufferAsBINARY' requested here
CASE_INVOKE_BY_TYPE(ReadPointsBufferAsBINARY, inputFile)
^
So would you also want us to drop long double
support from itk::VTKPolyDataMeshIO
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unsurprisingly, this endian swapping only affects IO classes.
As the other float types are being swapped, why not swap long double
as well? Just add size of the long double
to the list of the allowed sizes in the assert? @blowekamp what do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I quick google said 128-bit float may be an abnormal case:
https://www.talospace.com/2018/12/the-saga-of-power-isa-128-bit-long.html
So... Just leave it as a run time exception of now?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be fine to me to restore the itkGenericExceptionMacro("Cannot swap number of bytes requested")
that I originally proposed, and remove the compile-time static_assert(numberOfBytes is 2 or 4 or 8).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That should leave support for long double
if there is no need for endian swapping (the usual case).
Looking like a nice cleanup! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good even as-is.
9d241e9
to
3ed697e
Compare
3ed697e
to
beb0381
Compare
Aims to reduce code duplication. Inspired by a suggestion from Bradley Lowekamp at https://github.com/InsightSoftwareConsortium/ITK/pull/4841/files#r1751777344
beb0381
to
d44f513
Compare
Ready! We may of course reconsider/revisit |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great!
@thewtex Thanks, Matt! Please feel free to merge it! |
Aims to reduce code duplication. - Follow-up to pull request InsightSoftwareConsortium#4855 commit 3b04ad1 "STYLE: Clean-up ByteSwapper, using private `SwapBytes` helper function"
These nine `ByteSwapper` member functions were only for internal use. They are replaced now with private member functions `SwapBytes` and `SwapWriteRange`, by: - pull request InsightSoftwareConsortium#4855 commit 3b04ad1, and - pull request InsightSoftwareConsortium#4862 commit 9413dc4
Aims to reduce code duplication. Inspired by a suggestion from Bradley (@blowekamp) at https://github.com/InsightSoftwareConsortium/ITK/pull/4841/files#r1751777344